﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class _FlattedProfileSlottingCutter4
    {
        public static void FlattedProfileSlottingCutter4(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 2; //放大系数


            double dc = Convert.ToDouble(data["dc"]);
            double le = Convert.ToDouble(data["le"]);
            double lh = Convert.ToDouble(data["lh"]);
            double oal = Convert.ToDouble(data["oal"]);
            double dconms = Convert.ToDouble(data["dconms"]);
            double tp = Convert.ToDouble(data["tp"]);
            double d = le / tp;
            int i = (int)d;
            double popt = Convert.ToDouble(data["popt"]);
            double w1 = Convert.ToDouble(data["w1"]);
            double s1 = Convert.ToDouble(data["s1"]);
            var hand = "5";
            try
            {
                hand = data["hand"].ToString();
            }
            catch (Exception e)
            {
                Console.WriteLine("[hand] not found");
            }

            Vector2 v1 = new Vector2(-oal / 10 - oal -6 - dconms / 2, 0);
            Vector2 v2 = new Vector2(v1.X + oal + 4, v1.Y);
            Vector2 v3 = new Vector2(v1.X + 2, v1.Y + dc / 2);
            Vector2 v4 = new Vector2(v3.X + lh, v3.Y);
            Vector2 v5 = new Vector2(v4.X + 2, v1.Y + dconms / 2);
            Vector2 v6 = new Vector2(v3.X + oal, v5.Y);
            Vector2 v7 = new Vector2(v6.X, v6.Y * -1);
            Vector2 v8 = new Vector2(v5.X, v5.Y * -1);
            Vector2 v9 = new Vector2(v4.X, v4.Y * -1);
            Vector2 v10 = new Vector2(v3.X, v3.Y * -1);
            Vector2 v11 = new Vector2(v10.X, v10.Y - 0.8);
            Vector2 v12 = new Vector2(v11.X + tp / 2, v11.Y - popt);
            Vector2 v13 = new Vector2(v11.X + tp, v11.Y);
            Vector2 v14 = new Vector2(v12.X + tp, v12.Y);
            Vector2 v15 = new Vector2(v11.X + tp * i, v11.Y);
            Vector2 v16 = new Vector2(v15.X, v10.Y);
            Vector2 v17 = new Vector2(v16.X, v16.Y + w1 / 8.92);
            Vector2 v18 = new Vector2(v16.X + le / 22.82, v9.Y);
            Vector2 v22 = new Vector2(v10.X, v17.Y);
            Vector2 v21 = new Vector2(v22.X + le / 2.93, v22.Y);
            Vector2 v19 = new Vector2(v21.X + le / 6.474, v21.Y);
            Vector2 v20 = new Vector2(v21.X + (v19.X - v21.X) / 2, v16.Y);
            Vector2 v23 = new Vector2(v11.X, v11.Y * -1);
            Vector2 v24 = new Vector2(v15.X, v15.Y * -1);
            Vector2 v25 = new Vector2(v16.X, v16.Y * -1);
            Vector2 a1 = new Vector2(v10.X, v11.Y - popt / 4);
            Vector2 a2 = new Vector2(v16.X, a1.Y);
            Vector2 a3 = new Vector2(a1.X, v12.Y + popt / 8);
            Vector2 a4 = new Vector2(a2.X, a3.Y);
            Vector2 a5 = fun.Inters(v11, v12, a1, a2);
            Vector2 a6 = fun.Inters(v11, v12, a3, a4);
            Vector2 a7 = fun.Inters(v12, v13, a3, a4);
            Vector2 a8 = fun.Inters(v12, v13, a1, a2);
            Vector2 a9 = fun.Inters(v13, v14, a1, a2);
            Vector2 a10 = new Vector2(a8.X + tp * (i - 1), a8.Y);
            Vector2 a11 = new Vector2(a5.X, a5.Y * -1);
            Vector2 a12 = new Vector2(a6.X, a6.Y * -1);
            Vector2 a13 = new Vector2(a7.X, a7.Y * -1);
            Vector2 a14 = new Vector2(a8.X, a8.Y * -1);
            Vector2 a15 = new Vector2(a9.X, a9.Y * -1);
            Vector2 a16 = new Vector2(a10.X, a10.Y * -1);
            Vector2 v26 = new Vector2(v3.X, v1.Y + s1 / 2);
            Vector2 v27 = new Vector2(v25.X, v26.Y);
            Vector2 v28 = new Vector2(v26.X, v26.Y - s1);
            Vector2 v29 = new Vector2(v27.X, v28.Y);
            Vector2 v30 = new Vector2(a6.X, v26.Y);
            Vector2 v31 = new Vector2(v30.X, v28.Y);
            Vector2 v32 = new Vector2(a7.X, v26.Y);
            Vector2 v33 = new Vector2(v32.X, v28.Y);
            Vector2 v34 = new Vector2(a8.X, v26.Y);
            Vector2 v35 = new Vector2(v34.X, v28.Y);
            Vector2 v36 = new Vector2(a9.X, v26.Y);
            Vector2 v37 = new Vector2(v36.X, v28.Y);
            Vector2 v38 = new Vector2(v22.X + le / 9.6, v22.Y + (v28.Y - v22.Y) / 2.744);
            Vector2 v39 = new Vector2(v20.X, v38.Y);
            Vector2 v40 = new Vector2(v17.X - le / 4.624, v39.Y);
         



            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v3));
            line2.Vertexes.Add(new LwPolylineVertex(v4));
            line2.Vertexes.Add(new LwPolylineVertex(v5));
            line2.Vertexes.Add(new LwPolylineVertex(v6));
            line2.Vertexes.Add(new LwPolylineVertex(v7));
            line2.Vertexes.Add(new LwPolylineVertex(v8));
            line2.Vertexes.Add(new LwPolylineVertex(v9));
            line2.Vertexes.Add(new LwPolylineVertex(v10));
            line2.Vertexes.Add(new LwPolylineVertex(v3));
            line2.Vertexes.Add(new LwPolylineVertex(v4));
            line2.Vertexes.Add(new LwPolylineVertex(v9));
            line2.Vertexes.Add(new LwPolylineVertex(v8));
            line2.Vertexes.Add(new LwPolylineVertex(v5));
            fun.PolyFill(dxf, line2, 0.1, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v21));
            line3.Vertexes.Add(new LwPolylineVertex(v22));
            line3.Vertexes.Add(new LwPolylineVertex(v11));
            line3.Vertexes.Add(new LwPolylineVertex(a5));
            fun.PolyFill(dxf, line3, 0.1, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v19));
            line4.Vertexes.Add(new LwPolylineVertex(v17));
            line4.Vertexes.Add(new LwPolylineVertex(v18));
            line4.Vertexes.Add(new LwPolylineVertex(v16));
            line4.Vertexes.Add(new LwPolylineVertex(v17));
            line4.Vertexes.Add(new LwPolylineVertex(v15));
            line4.Vertexes.Add(new LwPolylineVertex(a10));
            fun.PolyFill(dxf, line4, 0.1, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(a5));
            line5.Vertexes.Add(new LwPolylineVertex(a6));
            line5.Vertexes.Add(new LwPolylineVertex(a7));
            line5.Vertexes.Add(new LwPolylineVertex(a8));
            fun.PolyFill(dxf, line5, 0.1, contour);

            fun.aray1(dxf, line5, 0, tp, i, 0.1, contour);

            LwPolyline line6 = new LwPolyline();
            line6.Vertexes.Add(new LwPolylineVertex(a8));
            line6.Vertexes.Add(new LwPolylineVertex(a9));
            fun.PolyFill(dxf, line6, 0.1, contour);

            fun.aray1(dxf, line6, 0, tp, i - 1, 0.1, contour);

            Arc arc1 = fun.DrawArc3(v21, v20, v19);
            fun.drawBArc(dxf, arc1, 0.1, contour);

            LwPolyline line7 = new LwPolyline();
            line7.Vertexes.Add(new LwPolylineVertex(a11));
            line7.Vertexes.Add(new LwPolylineVertex(a12));
            line7.Vertexes.Add(new LwPolylineVertex(a13));
            line7.Vertexes.Add(new LwPolylineVertex(a14));
            fun.PolyFill(dxf, line7, 0.1, contour);

            fun.aray1(dxf, line7, 0, tp, i, 0.1, contour);

            LwPolyline line8 = new LwPolyline();
            line8.Vertexes.Add(new LwPolylineVertex(a14));
            line8.Vertexes.Add(new LwPolylineVertex(a15));
            fun.PolyFill(dxf, line8, 0.1, contour);

            fun.aray1(dxf, line8, 0, tp, i - 1, 0.1, contour);

            LwPolyline line9 = new LwPolyline();
            line9.Vertexes.Add(new LwPolylineVertex(a11));
            line9.Vertexes.Add(new LwPolylineVertex(v23));
            line9.Vertexes.Add(new LwPolylineVertex(v3));
            line9.Vertexes.Add(new LwPolylineVertex(v25));
            line9.Vertexes.Add(new LwPolylineVertex(v24));
            line9.Vertexes.Add(new LwPolylineVertex(a16));
            fun.PolyFill(dxf, line9, 0.1, contour);

            LwPolyline line10 = new LwPolyline();
            line10.Vertexes.Add(new LwPolylineVertex(v30));
            line10.Vertexes.Add(new LwPolylineVertex(v31));
            line10.Vertexes.Add(new LwPolylineVertex(v33));
            line10.Vertexes.Add(new LwPolylineVertex(v32));
            fun.PolyFill(dxf, line10, 0.1, contour);

            fun.aray1(dxf, line10, 0, tp, i, 0.1, contour);

            LwPolyline line11 = new LwPolyline();
            line11.Vertexes.Add(new LwPolylineVertex(v34));
            line11.Vertexes.Add(new LwPolylineVertex(v35));
            line11.Vertexes.Add(new LwPolylineVertex(v37));
            line11.Vertexes.Add(new LwPolylineVertex(v36));
            fun.PolyFill(dxf, line11, 0.1, contour);

            fun.aray1(dxf, line11, 0, tp, i - 1, 0.1, contour);

            LwPolyline line12 = new LwPolyline();
            line12.Vertexes.Add(new LwPolylineVertex(v26));
            line12.Vertexes.Add(new LwPolylineVertex(v27));
            line12.Vertexes.Add(new LwPolylineVertex(v29));
            line12.Vertexes.Add(new LwPolylineVertex(v28));
            fun.PolyFill(dxf, line12, 0.1, contour);


            fun.drawcircle(dxf, v38, (v28.Y - v22.Y) / 8.11, 0.1, contour);

            fun.drawcircle(dxf, v38, (v28.Y - v22.Y) / 3.04, 0.1, contour);

            fun.drawcircle(dxf, v39, (v28.Y - v22.Y) / 8.11, 0.1, contour);

            fun.drawcircle(dxf, v39, (v28.Y - v22.Y) / 3.04, 0.1, contour);

            fun.drawcircle(dxf, v40, (v28.Y - v22.Y) / 8.11, 0.1, contour);

            fun.drawcircle(dxf, v40, (v28.Y - v22.Y) / 3.04, 0.1, contour);

            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;


            fun.dimrot1(dxf, v3, v10, 90, dc / 2, 1, height, arrowsize, exline, "dc=" + dc, "", "");

            fun.dimrot1(dxf, v11, v19, 180, dc, 1, height, arrowsize, exline, "lh=" + lh, "", "");

            fun.dimrot1(dxf, v11, v7, 180, dc * 2, 1, height, arrowsize, exline, "oal=" + oal, "", "");

            fun.dimrot1(dxf, v7, v6, -90, dc / 3, 1, height, arrowsize, exline, "dconms=" + dconms, "", "");



            if (hand.Equals("4"))
            {
                double g = 4;

                Vector2 v41 = new Vector2(v2.X + oal / 10, v2.Y);
                Vector2 v42 = new Vector2(v41.X + dconms + 4, v41.Y);
                Vector2 v43 = new Vector2(v41.X + 2 + dconms / 2,v41.Y );
                Vector2 v44 = new Vector2(v43.X, v43.Y + dconms / 2 + 2);
                Vector2 v45 = new Vector2(v43.X, v43.Y - dconms / 2 - 2);
                Vector2 v46 = new Vector2(v43.X + s1 / 2.859, a12.Y);
                Vector2 v47 = new Vector2(v43.X - s1 / 2.859, v46.Y);
                Vector2 v48 = new Vector2(v47.X, v23.Y);
                Vector2 v49 = new Vector2(v43.X - s1 / 2, v48.Y - (v23.Y - v3.Y) / 2);
                Vector2 v50 = new Vector2(v49.X, v46.Y - w1);
                Vector2 v51 = new Vector2(v50.X + s1, v50.Y);
                Vector2 v52 = new Vector2(v51.X, v49.Y);
                Vector2 v53 = new Vector2(v46.X, v48.Y);
                Vector2 v54 = new Vector2(v51.X, v3.Y);
                Vector2 v55 = new Vector2(v50.X, v54.Y);
                Vector2 v56 = fun.rotatePoint_Changed(v43, v55, -90);
                Vector2 v57 = fun.Polar(v43, 180 / g * pi / 180, Math.Sqrt(s1 * s1 / 4 + (v54.Y - v43.Y) * (v54.Y - v43.Y)));
                Vector2 v58 = fun.rotatePoint_Changed(v43, v54, -90);
                Vector2 v59 = fun.rotatePoint_Changed(v43, v57, -90);
                Vector2 v60 = fun.rotatePoint_Changed(v43, v56, -90);
                Vector2 v61 = fun.rotatePoint_Changed(v43, v58, -90);
                Vector2 v62 = fun.rotatePoint_Changed(v43, v59, -90);
                Vector2 v63 = fun.rotatePoint_Changed(v43, v60, -90);
                Vector2 v64 = fun.rotatePoint_Changed(v43, v61, -90);
                Vector2 v65 = fun.rotatePoint_Changed(v43, v62, -90);




                LwPolyline line13 = new LwPolyline();
                line13.Vertexes.Add(new LwPolylineVertex(v53));
                line13.Vertexes.Add(new LwPolylineVertex(v46));
                line13.Vertexes.Add(new LwPolylineVertex(v47));
                line13.Vertexes.Add(new LwPolylineVertex(v48));
                line13.Vertexes.Add(new LwPolylineVertex(v53));
                line13.Vertexes.Add(new LwPolylineVertex(v52));
                line13.Vertexes.Add(new LwPolylineVertex(v51));
                line13.Vertexes.Add(new LwPolylineVertex(v50));
                line13.Vertexes.Add(new LwPolylineVertex(v49));
                line13.Vertexes.Add(new LwPolylineVertex(v48));
                fun.PolyFill(dxf, line13, 0.1, contour);

                LwPolyline line14 = new LwPolyline();
                line14.Vertexes.Add(new LwPolylineVertex(v53));
                line14.Vertexes.Add(new LwPolylineVertex(v46));
                line14.Vertexes.Add(new LwPolylineVertex(v47));
                line14.Vertexes.Add(new LwPolylineVertex(v48));
                line14.Vertexes.Add(new LwPolylineVertex(v53));
                line14.Vertexes.Add(new LwPolylineVertex(v52));
                line14.Vertexes.Add(new LwPolylineVertex(v51));
                line14.Vertexes.Add(new LwPolylineVertex(v50));
                line14.Vertexes.Add(new LwPolylineVertex(v49));
                line14.Vertexes.Add(new LwPolylineVertex(v48));
                fun.PolyFill(dxf, line14, 0.1, contour);

                LwPolyline line15 = new LwPolyline();
                line15.Vertexes.Add(new LwPolylineVertex(v53));
                line15.Vertexes.Add(new LwPolylineVertex(v46));
                line15.Vertexes.Add(new LwPolylineVertex(v47));
                line15.Vertexes.Add(new LwPolylineVertex(v48));
                line15.Vertexes.Add(new LwPolylineVertex(v53));
                line15.Vertexes.Add(new LwPolylineVertex(v52));
                line15.Vertexes.Add(new LwPolylineVertex(v51));
                line15.Vertexes.Add(new LwPolylineVertex(v50));
                line15.Vertexes.Add(new LwPolylineVertex(v49));
                line15.Vertexes.Add(new LwPolylineVertex(v48));
                fun.PolyFill(dxf, line15, 0.1, contour);

                LwPolyline line16 = new LwPolyline();
                line16.Vertexes.Add(new LwPolylineVertex(v53));
                line16.Vertexes.Add(new LwPolylineVertex(v46));
                line16.Vertexes.Add(new LwPolylineVertex(v47));
                line16.Vertexes.Add(new LwPolylineVertex(v48));
                line16.Vertexes.Add(new LwPolylineVertex(v53));
                line16.Vertexes.Add(new LwPolylineVertex(v52));
                line16.Vertexes.Add(new LwPolylineVertex(v51));
                line16.Vertexes.Add(new LwPolylineVertex(v50));
                line16.Vertexes.Add(new LwPolylineVertex(v49));
                line16.Vertexes.Add(new LwPolylineVertex(v48));
                fun.PolyFill(dxf, line16, 0.1, contour);



                LwPolyline line17 =fun.rotateorigin(90 * pi / 180, line14);
                fun.PolyFill(dxf, line17, 0.1, contour);

                LwPolyline line18 = fun.rotateorigin(-90 * pi / 180, line15);
                fun.PolyFill(dxf, line18, 0.1, contour);

                LwPolyline line19 = fun.rotateorigin(180 * pi / 180, line16);
                fun.PolyFill(dxf, line19, 0.1, contour);

                fun.drawcircle(dxf, v43, dconms / 2, 0.1, contour);


                Arc arc2 = fun.DrawArc3(v56, v57, v54);
                fun.drawBArc(dxf, arc2, 0.1, contour);

                Arc arc3 = fun.DrawArc3(v60, v59, v58);
                fun.drawBArc(dxf, arc3, 0.1, contour);

                Arc arc4 = fun.DrawArc3(v63, v62, v61);
                fun.drawBArc(dxf, arc4, 0.1, contour);

                Arc arc5 = fun.DrawArc3(v55, v65, v64);
                fun.drawBArc(dxf, arc5, 0.1, contour);

                Line line20 = new Line(v41, v42);
                line20.Layer = centre;
                line20.Linetype = Linetype.DashDot;
                line20.LinetypeScale = 3;
                dxf.AddEntity(line20);

                Line line21 = new Line(v44, v45);
                line21.Layer = centre;
                line21.Linetype = Linetype.DashDot;
                line21.LinetypeScale = 3;
                dxf.AddEntity(line21);

            }

            if (hand.Equals("5"))
            {
                double g = 5;

                Vector2 v41 = new Vector2(v2.X + oal / 10, v2.Y);
                Vector2 v42 = new Vector2(v41.X + dconms + 4, v41.Y);
                Vector2 v43 = new Vector2(v41.X + 2 + dconms / 2, v41.Y);
                Vector2 v44 = new Vector2(v43.X, v43.Y + dconms / 2 + 2);
                Vector2 v45 = new Vector2(v43.X, v43.Y - dconms / 2 - 2);
                Vector2 v46 = new Vector2(v43.X + s1 / 2.859, a12.Y);
                Vector2 v47 = new Vector2(v43.X - s1 / 2.859, v46.Y);
                Vector2 v48 = new Vector2(v47.X, v23.Y);
                Vector2 v49 = new Vector2(v43.X - s1 / 2, v48.Y - (v23.Y - v3.Y) / 2);
                Vector2 v50 = new Vector2(v49.X, v46.Y - w1);
                Vector2 v51 = new Vector2(v50.X + s1, v50.Y);
                Vector2 v52 = new Vector2(v51.X, v49.Y);
                Vector2 v53 = new Vector2(v46.X, v48.Y);
                Vector2 v54 = new Vector2(v51.X, v3.Y);
                Vector2 v55 = new Vector2(v50.X, v54.Y);
                Vector2 v56 = fun.rotatePoint_Changed(v43, v55, -72);
                Vector2 v57 = fun.Polar(v43, 180 / g * pi / 180, Math.Sqrt(s1 * s1 / 4 + (v54.Y - v43.Y) * (v54.Y - v43.Y)));
                Vector2 v58 = fun.rotatePoint_Changed(v43, v54, -72);
                Vector2 v59 = fun.rotatePoint_Changed(v43, v57, -72);
                Vector2 v60 = fun.rotatePoint_Changed(v43, v56, -72);
                Vector2 v61 = fun.rotatePoint_Changed(v43, v58, -72);
                Vector2 v62 = fun.rotatePoint_Changed(v43, v59, -72);
                Vector2 v63 = fun.rotatePoint_Changed(v43, v60, -72);
                Vector2 v64 = fun.rotatePoint_Changed(v43, v61, -72);
                Vector2 v65 = fun.rotatePoint_Changed(v43, v62, -72);
                Vector2 v66 = fun.rotatePoint_Changed(v43, v63, -72);
                Vector2 v67 = fun.rotatePoint_Changed(v43, v64, -72);
                Vector2 v68 = fun.rotatePoint_Changed(v43, v65, -72);




                LwPolyline line13 = new LwPolyline();
                line13.Vertexes.Add(new LwPolylineVertex(v53));
                line13.Vertexes.Add(new LwPolylineVertex(v46));
                line13.Vertexes.Add(new LwPolylineVertex(v47));
                line13.Vertexes.Add(new LwPolylineVertex(v48));
                line13.Vertexes.Add(new LwPolylineVertex(v53));
                line13.Vertexes.Add(new LwPolylineVertex(v52));
                line13.Vertexes.Add(new LwPolylineVertex(v51));
                line13.Vertexes.Add(new LwPolylineVertex(v50));
                line13.Vertexes.Add(new LwPolylineVertex(v49));
                line13.Vertexes.Add(new LwPolylineVertex(v48));
                fun.PolyFill(dxf, line13, 0.1, contour);

                LwPolyline line14 = new LwPolyline();
                line14.Vertexes.Add(new LwPolylineVertex(v53));
                line14.Vertexes.Add(new LwPolylineVertex(v46));
                line14.Vertexes.Add(new LwPolylineVertex(v47));
                line14.Vertexes.Add(new LwPolylineVertex(v48));
                line14.Vertexes.Add(new LwPolylineVertex(v53));
                line14.Vertexes.Add(new LwPolylineVertex(v52));
                line14.Vertexes.Add(new LwPolylineVertex(v51));
                line14.Vertexes.Add(new LwPolylineVertex(v50));
                line14.Vertexes.Add(new LwPolylineVertex(v49));
                line14.Vertexes.Add(new LwPolylineVertex(v48));
                fun.PolyFill(dxf, line14, 0.1, contour);

                LwPolyline line15 = new LwPolyline();
                line15.Vertexes.Add(new LwPolylineVertex(v53));
                line15.Vertexes.Add(new LwPolylineVertex(v46));
                line15.Vertexes.Add(new LwPolylineVertex(v47));
                line15.Vertexes.Add(new LwPolylineVertex(v48));
                line15.Vertexes.Add(new LwPolylineVertex(v53));
                line15.Vertexes.Add(new LwPolylineVertex(v52));
                line15.Vertexes.Add(new LwPolylineVertex(v51));
                line15.Vertexes.Add(new LwPolylineVertex(v50));
                line15.Vertexes.Add(new LwPolylineVertex(v49));
                line15.Vertexes.Add(new LwPolylineVertex(v48));
                fun.PolyFill(dxf, line15, 0.1, contour);

                LwPolyline line16 = new LwPolyline();
                line16.Vertexes.Add(new LwPolylineVertex(v53));
                line16.Vertexes.Add(new LwPolylineVertex(v46));
                line16.Vertexes.Add(new LwPolylineVertex(v47));
                line16.Vertexes.Add(new LwPolylineVertex(v48));
                line16.Vertexes.Add(new LwPolylineVertex(v53));
                line16.Vertexes.Add(new LwPolylineVertex(v52));
                line16.Vertexes.Add(new LwPolylineVertex(v51));
                line16.Vertexes.Add(new LwPolylineVertex(v50));
                line16.Vertexes.Add(new LwPolylineVertex(v49));
                line16.Vertexes.Add(new LwPolylineVertex(v48));
                fun.PolyFill(dxf, line16, 0.1, contour);

                LwPolyline line116 = new LwPolyline();
                line116.Vertexes.Add(new LwPolylineVertex(v53));
                line116.Vertexes.Add(new LwPolylineVertex(v46));
                line116.Vertexes.Add(new LwPolylineVertex(v47));
                line116.Vertexes.Add(new LwPolylineVertex(v48));
                line116.Vertexes.Add(new LwPolylineVertex(v53));
                line116.Vertexes.Add(new LwPolylineVertex(v52));
                line116.Vertexes.Add(new LwPolylineVertex(v51));
                line116.Vertexes.Add(new LwPolylineVertex(v50));
                line116.Vertexes.Add(new LwPolylineVertex(v49));
                line116.Vertexes.Add(new LwPolylineVertex(v48));
                fun.PolyFill(dxf, line116, 0.1, contour);



                LwPolyline line17 = fun.rotateorigin(72 * pi / 180, line14);
                fun.PolyFill(dxf, line17, 0.1, contour);

                LwPolyline line18 = fun.rotateorigin(-72 * pi / 180, line15);
                fun.PolyFill(dxf, line18, 0.1, contour);

                LwPolyline line19 = fun.rotateorigin(144 * pi / 180, line16);
                fun.PolyFill(dxf, line19, 0.1, contour);

                LwPolyline line119 = fun.rotateorigin(-144 * pi / 180, line116);
                fun.PolyFill(dxf, line119, 0.1, contour);

                fun.drawcircle(dxf, v43, dconms / 2, 0.1, contour);


                Arc arc2 = fun.DrawArc3(v56, v57, v54);
                fun.drawBArc(dxf, arc2, 0.1, contour);

                Arc arc3 = fun.DrawArc3(v60, v59, v58);
                fun.drawBArc(dxf, arc3, 0.1, contour);

                Arc arc4 = fun.DrawArc3(v63, v62, v61);
                fun.drawBArc(dxf, arc4, 0.1, contour);

                Arc arc5 = fun.DrawArc3(v66, v65, v64);
                fun.drawBArc(dxf, arc5, 0.1, contour);

                Arc arc6 = fun.DrawArc3(v55, v68, v67);
                fun.drawBArc(dxf, arc6, 0.1, contour);

                Line line20 = new Line(v41, v42);
                line20.Layer = centre;
                line20.Linetype = Linetype.DashDot;
                line20.LinetypeScale = 3;
                dxf.AddEntity(line20);

                Line line21 = new Line(v44, v45);
                line21.Layer = centre;
                line21.Linetype = Linetype.DashDot;
                line21.LinetypeScale = 3;
                dxf.AddEntity(line21);


            }


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);

            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}